package com.nodecollege.cloud.controller.admin;

import com.nodecollege.cloud.common.annotation.AdminLoginAnnotation;
import com.nodecollege.cloud.common.annotation.ApiAnnotation;
import com.nodecollege.cloud.common.model.BindVO;
import com.nodecollege.cloud.common.model.NCResult;
import com.nodecollege.cloud.common.model.QueryVO;
import com.nodecollege.cloud.common.model.po.UpmsAdmin;
import com.nodecollege.cloud.common.model.po.UpmsMenu;
import com.nodecollege.cloud.common.model.po.UpmsOpRole;
import com.nodecollege.cloud.common.model.po.UpmsOpRoleAdmin;
import com.nodecollege.cloud.common.model.vo.MenuTreeVO;
import com.nodecollege.cloud.service.OpRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LC
 * @date 2020/2/18 22:46
 */
@RestController
@AdminLoginAnnotation
@RequestMapping("/admin/opRole")
public class OpRoleController {

    @Autowired
    private OpRoleService opRoleService;

    /**
     * 查询运营角色列表
     *
     * @param queryVO
     * @return
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "查询运营角色列表")
    @PostMapping("/getOpRoleList")
    public NCResult<UpmsOpRole> getOpRoleList(@RequestBody QueryVO<UpmsOpRole> queryVO) {
        return opRoleService.getOpRoleList(queryVO);
    }

    /**
     * 添加运营角色
     *
     * @param opRole
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "添加运营角色")
    @PostMapping("/addOpRole")
    public NCResult addOpRole(@RequestBody UpmsOpRole opRole) {
        opRoleService.addOpRole(opRole);
        return NCResult.ok("添加角色成功");
    }

    /**
     * 更新运营角色列表
     *
     * @param opRole
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "更新运营角色")
    @PostMapping("/updateOpRole")
    public NCResult updateOpRole(@RequestBody UpmsOpRole opRole) {
        opRoleService.updateOpRole(opRole);
        return NCResult.ok();
    }

    /**
     * 删除运营角色列表
     *
     * @param opRole
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "删除运营角色")
    @PostMapping("/delOpRole")
    NCResult delOpRole(@RequestBody UpmsOpRole opRole) {
        opRoleService.delOpRole(opRole);
        return NCResult.ok();
    }

    /**
     * 查询所有运营菜单树
     *
     * @return
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "查询所有运营菜单树")
    @PostMapping("/getOpMenuTree")
    public NCResult<MenuTreeVO> getOpMenuTree() {
        return NCResult.ok(opRoleService.getOpMenuTree());
    }

    /**
     * 根据运营角色查询运营菜单
     *
     * @param opRole
     * @return
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "根据运营角色查询运营菜单")
    @PostMapping("/getOpRoleMenuList")
    public NCResult<UpmsMenu> getOpRoleMenuList(@RequestBody UpmsOpRole opRole) {
        return NCResult.ok(opRoleService.getOpRoleMenuList(opRole));
    }

    /**
     * 绑定解绑运营角色菜单信息
     *
     * @param bindVO
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "绑定解绑运营角色菜单信息")
    @PostMapping("/bindOpRoleMenu")
    public NCResult bindOpRoleMenu(@RequestBody BindVO bindVO) {
        bindVO.setMainSource(true);
        opRoleService.bindOpRoleMenu(bindVO);
        return NCResult.ok();
    }

    /**
     * 根据角色信息查询绑定的管理员信息
     *
     * @param queryVO
     * @return
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "查询绑定的管理员")
    @PostMapping("/getAdminListByOpRole")
    public NCResult<UpmsAdmin> getAdminListByOpRole(@RequestBody QueryVO<UpmsOpRoleAdmin> queryVO) {
        return opRoleService.getAdminListByOpRole(queryVO);
    }

    /**
     * 绑定角色管理员
     *
     * @param bindVO
     * @return
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "绑定角色管理员")
    @PostMapping("/bindOpRoleAdmin")
    public NCResult bindOpRoleAdmin(@RequestBody BindVO bindVO) {
        bindVO.setMainSource(true);
        return opRoleService.bindOpRoleAdmin(bindVO);
    }

    /**
     * 解除运营角色管理员绑定
     *
     * @param opRoleAdmin
     */
    @ApiAnnotation(modularName = "运营角色管理", description = "解绑角色管理员")
    @PostMapping("/unBindOpRoleAdmin")
    public NCResult unBindOpRoleAdmin(@RequestBody UpmsOpRoleAdmin opRoleAdmin) {
        opRoleService.unBindOpRoleAdmin(opRoleAdmin);
        return NCResult.ok();
    }
}
